package com.haidong.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//servlet的url可以设置多个
//url匹配还有目录匹配,扩展名匹配,任意匹配
//精确匹配>目录匹配>扩展名匹配>/*>/
//目录匹配,例如/demo/*表示demo下的任意目录
//扩展名匹配,例如/demo/*.mp3表示demo下任意mp3扩展名
//,/匹配会覆盖掉默认的servlet,当其他都连不上会连这个
//,/*表示匹配任意访问路径,但是优先级仅高于/所以相当于精确,目录和扩展名都匹配不上的选择
@WebServlet(urlPatterns = {"/demo2","/demo21"})
public class servletDemo2 extends HttpServlet {
    /**
     * 直接访问该servlet默认是调用doget
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get");
    }

    /**
     * 通过html中提交表单修改为post并链接到该servlet路径可以调用dopost
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("post");
    }
}
